<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020-12-02
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <base href="<%=request.getContextPath()%>/"/>
  <link rel="stylesheet" href="webjars/layui/2.5.6/css/layui.css">
</head>
<body>
        <div class="layui-main">
            <script type="text/html" id="toolbar">
                <div class="layui-form-item">
                    <form class="layui-form" id="tou">
                        <label class="layui-form-label">物资名:</label>
                        <input type="text" name="cgName" id="cgName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left">
                        <button type="button" class="layui-btn" onclick="search()" style="float: left;margin-left: 20px">查询</button>
                    </form>
                        <button class="layui-btn" lay-event="add" onclick="add()" style="margin-left: 20px">添加</button>
                </div>
            </script>
            <table id="roleTb" lay-filter="roleTb"></table>
            <script type="text/html" id="action">
                <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>


        <div style="display: none" id="update">
            <form class="layui-form"  action="" lay-filter="update">
                <input type="hidden" name="id"/>
                <div class="layui-form-item" style="margin-top: 30px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">物资名称:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">物资编码:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">助记码:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">最小规格:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">最小单位:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">包装单位:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">包装规格:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">生产厂家:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
                    <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">--%>
                    <label class="layui-form-label" style="margin-bottom: 20px">是否禁用:</label>
                    <input type="text" name="deleteFlag" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
                    <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                        <select name="city" lay-verify="required">
                            <option value=""></option>
                            <option value="0">北京</option>
                            <option value="1">上海</option>
                            <option value="2">广州</option>
                            <option value="3">深圳</option>
                            <option value="4">杭州</option>
                        </select>
                    </div>--%>
                </div>
            </form>
        </div>



        <div style="display: none" id="add">
            <form class="layui-form"  action="" lay-filter="add">
                <div class="layui-form-item" style="margin-top: 30px">
                    <input name="dictionaryId" type="hidden"/>
                    <label class="layui-form-label" style="margin-bottom: 20px">物资名称:</label>
                    <input type="text" name="cgName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">物资编码:</label>
                    <input type="text" name="cgCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">--%>
                    <label class="layui-form-label" style="margin-bottom: 20px">助记码:</label>
                    <input type="text" name="inputCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">最小规格:</label>
                    <input type="text" name="spec" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">最小单位:</label>
                    <input type="text" name="unit" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">包装单位:</label>
                    <input type="text" name="packUnit" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">包装规格:</label>
                    <input type="text" name="packSpec" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <label class="layui-form-label" style="margin-bottom: 20px">生产厂家:</label>
                    <input type="text" name="factory" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>--%>
                    <input type="hidden" value="医用服装" name="type" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">是否禁用:</label>--%>
                    <input type="hidden" value="y" name="deleteFlag" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">创建者:</label>--%>
                    <input type="hidden" value="小老弟" name="createBy" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                    <%--<label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
                    <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                        <select name="city" lay-verify="required">
                            <option value=""></option>
                            <option value="0">北京</option>
                            <option value="1">上海</option>
                            <option value="2">广州</option>
                            <option value="3">深圳</option>
                            <option value="4">杭州</option>
                        </select>
                    </div>--%>
                </div>

            </form>
        </div>




            <div id="tree"></div>

<script src="webjars/layui/2.5.6/layui.js"></script>
<script>
        //表格初始化
        layui.use(["table"],function () {
            let table=layui.table;
            table.render({
                id:"roleTb",
                elem:"#roleTb",
                url:"wz/search",
                toolbar: "#toolbar",
                page: true,
                cols:[[
                    {title:"物资编码",field:"cgCode"},
                    {title:"物资名称",field:"cgName"},
                    {title:"助记码",field:"inputCode"},
                    {title:"最小规格",field:"spec"},
                    {title:"最小单位",field:"unit"},
                    {title:"包装单位",field:"packUnit"},
                    {title:"包装规格",field:"packSpec"},
                    {title:"生产厂家",field:"factory"},
                    {title:"物资类别",field:"type"},
                    //{title:"是否可用",field:"deleteFlag"},
                    {title: "操作",toolbar:"#action"}
                ]]
            })
            table.on("tool(roleTb)",function ({data,event}){
                switch (event) {
                    case "update":
                        update(data);
                        break;
                    case "del":
                        del(data.dictionaryId);
                        break;
                }
            });



        })



        function add(){
            layui.use(["layer","jquery","form","table"],function(){
                let $ = layui.$;
                let form = layui.form;
                let layer = layui.layer;
                let table = layui.table;
                $("#add>form")[0].reset();
                layer.open({
                    type:1,
                    offset:'50px',
                    skin:'layui-layer-molv',
                    area:["700px","450px"],
                    content:$("#add"),
                    btn:["确定","取消"],
                    yes(){
                        let params=form.val("add");
                        console.log(params);
                        $.post("wz/add",params)
                            .done(({msg})=>{
                                table.reload("roleTb");
                                layer.close(layer.index);
                                layer.msg(msg);
                            });
                    }
                });
            });
        }





        //修改
        function update(data) {
            //console.log(data);
            layui.use(["layer","jquery","form"],function () {
                let layer=layui.layer;
                let $=layui.$;
                layui.form.val("update",data);
                layer.open({
                    type:1,
                    offset:'50px',
                    skin:'layui-layer-molv',
                    area:["700px","450px"],
                    content:$("#update"),
                    btn:["确定","取消"],
                    yes(){
                        let params=layui.form.val("update");
                        $.post("wz/update",params)
                        .done(({msg})=>{
                            layer.close(layer.index);
                            layer.msg(msg);
                            layui.table.reload("roleTb");
                        });
                    }
                })
            })
        }








        function del(dictionaryId){
            layui.use("jquery",function(){
                alert(dictionaryId);
                let layer=layui.layer;
                layui.$.post('/wz/del/',{dictionaryId:dictionaryId})
                    .done(({msg})=>{
                        layui.table.reload("roleTb");
                        layer.msg(msg);
                    });
            });
        }



        function search() {
            layui.use('table', function() {
                let table = layui.table;
                table.reload('roleTb', {where: {cgName: document.getElementById('cgName').value}});
            })
        }



</script>
</body>
</html>
